{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from sklearn.metrics import classification_report  # 评估模型的。准确率，召回率，F1等\n",
    "from sklearn import preprocessing \n",
    "# 数据是否需要标准化,用了标准化，数值会更加优化\n",
    "scale = False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD8CAYAAAB+UHOxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3X+wHWWd5/H3NyQYo2gwCQomuRcHFhFMIkkRKawVBn/ErAvrFlPqRisKVkoU80PdAcyO9zq71I7jDpgs41BZsWQ2kZlZZlELZQGVLXYKZLyhAgQRQQnxEhZCIIiFrAn57h99Djn35PzoPqd/PN39eVV13Xv69unznNPnPt/u5/s8T5u7IyIi9TOt6AKIiEgxFABERGpKAUBEpKYUAEREakoBQESkphQARERqSgFARKSmFABERGpKAUBEpKamF12AXubOneujo6NFF0NEpDS2b9/+jLvPi7Nt0AFgdHSUiYmJooshIlIaZvZ43G3VBCQiUlMKACIiNRU7AJjZt8zsaTPb2bJu3MyeMLMdjWVll+euMLOHzexRM7s8jYKLiMhwkuQAvg1cA/xt2/qr3f2/dHuSmR0F/DXwXmAS+JmZfd/df56wrAAcOHCAyclJXnrppUGeXgkzZ85k/vz5zJgxo+iiiEiJxQ4A7n6nmY0O8BpnAo+6+68BzOzvgAuAgQLA5OQkxxxzDKOjo5jZILsoNXdn3759TE5OcuKJJxZdHBEpsTRyAJea2f2NJqJjO/z9zcBvWh5PNtYN5KWXXmLOnDm1rPwBzIw5c+bU+g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Fdhddlpi+5u6L3H0JcDPw5aILFMPtwOnuvgj4JXBFweWJayfwb4E7iy5IL2Z2FPDXwAeAtwEfNbO3FVuqvr4NrCi6EAkdBL7g7qcC7wQ+W4LPGeD/AX/s7ouBJcAKM3tn1i9aigAAXA38KVCKhIW7/7bl4WsoQbnd/TZ3P9h4+FNgfpHlicvdH3L3MgwWPBN41N1/7e5/AP4OuKDgMvXk7ncCzxZdjiTc/Ul3v7fx+wvAQ8Cbiy1Vfx75XePhjMaSeb0RfAAws/OBJ9z9vqLLkoSZXWlmvwFWUY4rgFYXAbcUXYiKeTPwm5bHk5SgYiozMxsF3gHcU2xJ4jGzo8xsB/A0cLu7Z17uIEYCm9mPgDd1+NNG4EvA+/ItUX+9yuzu33P3jcBGM7sCuBQYy7WAHfQrc2ObjUSX0dvyLFsvccpdAp1uYRb8lWFZmdlrgX8E1rddkQfL3V8GljTybzeZ2enunmn+JYgA4O7v6bTezN4OnAjcZ9EtAOcD95rZme7+f3Ms4hG6lbmD7wA/IIAA0K/MZrYa+CBwngfUPzjBZx2ySWBBy+P5wJ6CylJpZjaDqPLf5u7/s+jyJOXu+83sfxPlXzINAEE3Abn7A+5+nLuPuvso0T/RGUVX/v2Y2cktD88HflFUWeIysxXAZcD57v5i0eWpoJ8BJ5vZiWZ2NPAR4PsFl6lyLDpTvA54yN2vKro8cZnZvGbPOzN7NfAecqg3gg4AJfYXZrbTzO4nar4qQ1e0a4BjgNsb3VevLbpAcZjZh8xsEjgL+IGZ3Vp0mTppJNgvBW4lSkz+g7s/WGypejOzG4C7gVPMbNLMLi66TDGcDXwc+OPG93iHma0sulAxHA/c0agzfkaUA7g56xfVSGARkZrSFYCISE0pAIiI1JQCgIhITSkAiIjUlAKAiEhNKQCIiNSUAoCISE0pAIiI1NT/B9TaoxvjcU4gAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 载入数据\n",
    "data = np.genfromtxt(\"LR-testSet.csv\", delimiter=\",\")\n",
    "x_data = data[:,:-1]\n",
    "y_data = data[:,-1]\n",
    "    \n",
    "def plot():  #画图\n",
    "    x0 = []  # 分0类别和1类别\n",
    "    x1 = []\n",
    "    y0 = []\n",
    "    y1 = []\n",
    "    # 切分不同类别的数据\n",
    "    for i in range(len(x_data)):\n",
    "        if y_data[i]==0:\n",
    "            x0.append(x_data[i,0])\n",
    "            y0.append(x_data[i,1])\n",
    "        else:\n",
    "            x1.append(x_data[i,0])\n",
    "            y1.append(x_data[i,1])\n",
    "\n",
    "    # 画图\n",
    "    scatter0 = plt.scatter(x0, y0, c='b', marker='o')  # 样式o是圆圈\n",
    "    scatter1 = plt.scatter(x1, y1, c='r', marker='x') # 样式是叉叉\n",
    "    #画图例\n",
    "    plt.legend(handles=[scatter0,scatter1],labels=['label0','label1'],loc='best')\n",
    "    \n",
    "plot()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(100, 2)\n",
      "(100, 1)\n",
      "(100, 3)\n"
     ]
    }
   ],
   "source": [
    "# 数据处理，添加偏置项\n",
    "x_data = data[:,:-1]\n",
    "y_data = data[:,-1,np.newaxis]\n",
    "\n",
    "print(np.mat(x_data).shape)\n",
    "print(np.mat(y_data).shape)\n",
    "# print(x_data)\n",
    "# 给样本添加偏置项\n",
    "X_data = np.concatenate((np.ones((100,1)),x_data),axis=1) # axis=1水平相加\n",
    "print(X_data.shape)\n",
    "# print(X_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](img/1.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](img/2.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 4  4]\n",
      " [21 24]]\n"
     ]
    }
   ],
   "source": [
    "# print (np.ones((2,2))*2)  # 生成2行四列全2矩阵\n",
    "l = [[1,2],\n",
    "     [3,4]]\n",
    "u = [[4,2],\n",
    "     [7,6]]\n",
    "print(np.multiply(l,u))  # 按位相乘"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 逻辑回归\n",
    "def sigmoid(x):  # hθ（x）\n",
    "    return 1.0/(1+np.exp(-x))\n",
    "\n",
    "def cost(xMat, yMat, ws):  # 逻辑回归的代价函数，训练数据，标签，权重\n",
    "    # 左右分别对应上图的-ylog(hθ(x))和-（1-y）log(1-h(θx))\n",
    "    # hθ（x） =g(x)是sigmoid函数，注意np.multiply是按位相乘,见上\n",
    "    left = np.multiply(yMat, np.log(sigmoid(xMat*ws)))\n",
    "    right = np.multiply(1 - yMat, np.log(1 - sigmoid(xMat*ws)))\n",
    "    return np.sum(left + right) / -(len(xMat))  # J（θ）\n",
    "\n",
    "def gradAscent(xArr, yArr):\n",
    "    \n",
    "    if scale == True: # 是否数据标准化\n",
    "        xArr = preprocessing.scale(xArr)\n",
    "    xMat = np.mat(xArr)\n",
    "    yMat = np.mat(yArr)\n",
    "    \n",
    "    lr = 0.001  # 学习率\n",
    "    epochs = 10000 # 迭代次数\n",
    "    costList = []   # 用来保存cost值\n",
    "    # 计算数据行列数\n",
    "    # 行代表数据个数（样本值），列代表权值个数（特征个数3）\n",
    "    m,n = np.shape(xMat)\n",
    "    # 初始化权值\n",
    "    ws = np.mat(np.ones((n,1)))\n",
    "    \n",
    "    for i in range(epochs+1):    # +1是方便下面每50次记录一次时，可以到最后一次         \n",
    "        # xMat和weights矩阵相乘\n",
    "        h = sigmoid(xMat*ws)   # 100x3， 3x1，组成100行1列，h是所有样本的输出hθ（x）\n",
    "        # 计算误差\n",
    "        ws_grad = xMat.T*(h - yMat)/m  # xMat.T是3x100，后面是100x1，组成3行1列，对应3个权值。\n",
    "        ws = ws - lr*ws_grad \n",
    "        \n",
    "        if i % 50 == 0: # 每迭代50保存cost函数\n",
    "            costList.append(cost(xMat,yMat,ws))\n",
    "    return ws,costList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 2.05836354]\n",
      " [ 0.3510579 ]\n",
      " [-0.36341304]]\n"
     ]
    }
   ],
   "source": [
    "# 训练模型，得到权值和cost值的变化\n",
    "ws,costList = gradAscent(X_data, y_data)\n",
    "print(ws)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD8CAYAAAB+UHOxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJztnXuYFOWV8H9nuAoqFwHlNjMoBBFEBAQUmNYlJogxJj7ubvyIEk2WlUS5xY0XkoU18fliLhp4sq4PiUncDzS7a6JmE03UxMwgF2XAEVDwjjhAuAoo15np8/3RF3qa7p7q7qqu6u7ze556uqu6LqeqZs5533POe15RVQzDMIzyo8JvAQzDMAx/MANgGIZRppgBMAzDKFPMABiGYZQpZgAMwzDKFDMAhmEYZYoZAMMwjDLFDIBhGEaZYgbAMAyjTGnvtwCZ6NWrl1ZXV/sthmEYRtGwbt26vara28m+gTYA1dXV1NfX+y2GYRhG0SAiHzjd11xAhmEYZYoZAMMwjDLFsQEQkV+IyG4R2ZSwbZGIbBeRhugyLc2xU0XkTRF5R0TuckNwwzAMIz+yiQH8Cvgp8J9J2x9U1R+lO0hE2gH/DlwJNAJrReR3qvpGlrIC0NTURGNjI8eOHcvl8JKgc+fODBgwgA4dOvgtimEYRYxjA6CqdSJSncM1xgHvqO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2ZBWRGcDngCnqcy5xFs81iDQCAxPWBwA7fJKl5BCRDkSU/3JV/a3f8jhBVQ+IyF+JxFo8NQAl6wJS1Y2q2kdVq1W1msg/2mi/lH9biMiQhNXPA1v8kqUtRGQqcCfweVU94rc8Rc5aYIiIDBKRjsCXgN/5LFNJIJGW3yPAZlV9wG95MiEivWPZdCJyGvBpCqADStYAFCHfF5FNIrKBiNsqsClrwE+BM4Dno2mrD/stUDpE5Isi0ghcCvxBRP7kt0yJRIPptwF/IhKk/G9Vfd1fqdIjIo8Dq4GhItIoIl/1W6YMTARuBP4u+nfaICLT/BYqDX2BF6P//2uJxAB+7/VFbSSwYRhGmWI9AMMwjDLFDIBhGEaZYgbAMAyjTDEDYBiGUaaYATAMwyhTzAAYhmGUKWYADMMwyhQzAIZhGGXK/wdRNQrpC9yjfQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "if scale == False: # 不做参数标准化\n",
    "    # 画图决策边界\n",
    "    plot() # 画的散点图\n",
    "    x_test = [[-4],[3]] # 直线的两个点的x值\n",
    "    y_test = (-ws[0] - x_test*ws[1])/ws[2]  # w0+x1w1+x2w2=0-->w0+xw1+yw2=0-->y=(-w0-xw1)/w2，怎么理解啊\n",
    "    plt.plot(x_test, y_test, 'k') # 黑色的线\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAEWCAYAAABliCz2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAFhtJREFUeJzt3XuQJWV9xvHn2Z3ZnWGvICOuLGGhpCQS5TaxQI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niTpNfYPjC1rl6TymaViFgbESsjYpWKY/fdiHiLpNsknZkWG7u/tb/DmWn5SOVnp6s7jpB0lIqTW7NSRDwh6THbL0xFr5J0vzI9ziq6ck6yfUD6N17b36yPc51pOa5p3jbbJ6W/49vq1tWZbp/gmIYTJGeouJrlZ5I+0O36THFfXq7iK9pPJN2VhjNU9F/eKumnaXxQWt6SPpH2/R5Jg3Xreoekh9Pw9m7vWwf7/ifaf5XOkSr+Iz8s6T8kLUzlfen1w2n+kXXv/0D6OzykCV650KX9PU7SUDrWX1dxNUa2x1nShyU9KOleSV9UcaVNdsdZ0jUqzlPsVtEiP386j6ukwfQ3/Jmkj2vMif92A7dWAICKmOtdOgCADhH4AFARBD4AVASBDwAVQeADQEUQ+Mie7Wdt31U3TNtdVW2vqr8zIjCb9bRfBJjzdkbEcd2uBNBttPBRWbYftX2J7TvS8IJUfrjtW9M9ym+1/Xup/BDb19u+Ow0vS6uab/tT6X7vN9vuT8u/2/b9aT1f6dJuAvsQ+KiC/jFdOmfVzdsaES9V8avFy1LZxyV9ISJeIulqSVek8isk/XdEHKvi3jf3pfKjJH0iIo6RtEXSn6fyiyUdn9bzN2XtHNApfmmL7NneHhGLG5Q/KunUiHgk3bTuiYh4ju0nVdy/fHcqfzwiDrY9LGllRIzUrWOVpFsi4qj0+h8k9UbER23fKGm7ilsnfD0itpe8q0BLtPBRddFkutkyjYzUTT+r/efGXqfiXiknStpYd2dIoCsIfFTdWXXj29P0/6i4e6ckvUXSD9L0rZLeJe17Du/SZiu1PU/SYRFxm4oHvCyXNO5bBjCTaHGgCvpt31X3+saIqF2audD2BhWNn3NS2bslfdb2+1Q8mertqXyNpHW2z1fRkn+XijsjNjJf0pdsL1NxV8R/i4gt07ZHwCTQh4/KSn34gxHxZLfrAswEunQAoCJo4QNARdDCB4CKIPABoCIIfACoCAIfACqCwAeAivh/WxWGwJSZUg4AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画图 loss值的变化\n",
    "x = np.linspace(0,10000,201) # 取0到10000，记录201次\n",
    "plt.plot(x, costList, c='r')\n",
    "plt.title('Train')\n",
    "plt.xlabel('Epochs')\n",
    "plt.ylabel('Cost')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             precision    recall  f1-score   support\n",
      "\n",
      "        0.0       0.82      1.00      0.90        47\n",
      "        1.0       1.00      0.81      0.90        53\n",
      "\n",
      "avg / total       0.92      0.90      0.90       100\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 预测\n",
    "def predict(x_data, ws):\n",
    "    if scale == True:\n",
    "        x_data = preprocessing.scale(x_data)\n",
    "    xMat = np.mat(x_data)\n",
    "    ws = np.mat(ws)\n",
    "    return [1 if x >= 0.5 else 0 for x in sigmoid(xMat*ws)]  # >=0.5返回1，否则返回0\n",
    "\n",
    "predictions = predict(X_data, ws)\n",
    "\n",
    "print(classification_report(y_data, predictions)) #sklearn用来计算准确率，召回率。F1的值，support指用100数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
